<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }

      #box {
        width: 6.9rem;
        height: 3rem;
        margin: 0.3rem;
        border: 1px solid black;
        box-sizing: border-box;
      }
    </style>
  </head>
  <body>
    <!-- 解决1px边框粗的问题方式二: 
    1. 盒子正常rem适配
    2. 1px 边框不参与适配

    3. 让布局视口整体变大. 像素比为2,变大两倍, 像素比为3. 变大3倍
  
  -->
    <div id="box"></div>
    <script>
      // 1. 动态的计算根标签字体大小
      const fontSize = (document.documentElement.clientWidth * 100) / 750

      // 2. 将计算好的根标签的字体大小,设置给html
      document.documentElement.style.fontSize = fontSize + 'px'

      // 让布局视口变大
      document.querySelector('meta[name=viewport]').content =
        'width=device-width, initial-scale=' + 1 / window.devicePixelRatio

      // 1px已经变细了,但是布局视口等比变大,显得盒子变小.最后需要将盒子也等比变大
      document.documentElement.style.fontSize =
        fontSize * window.devicePixelRatio  + 'px'
    </script>
  </body>
</html>
